package com.dfbz.service.impl;

import com.dfbz.dao.ArticleDao;
import com.dfbz.entity.Article;
import com.dfbz.entity.User;
import com.dfbz.service.ArticleService;
import com.dfbz.service.IService;
import com.github.pagehelper.PageHelper;
import com.github.pagehelper.PageInfo;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;

import javax.servlet.http.HttpServletRequest;
import javax.servlet.http.HttpSession;
import java.util.List;
import java.util.Map;

@Service
public class ArticleServiceImpl extends IServiceImpl<Article> implements ArticleService {

    @Autowired
    ArticleDao articleDao;

    @Override
    public PageInfo<Article> articleConditionPage(Integer pageNum, Integer pageSize, Map<String, String> map) {
        PageHelper.startPage(pageNum,pageSize);
       List<Article> dbArticleList=articleDao.articleConditionPage(map);

        PageInfo<Article> articlePageInfo = new PageInfo<>(dbArticleList);
        return articlePageInfo;
    }

    @Override
    public PageInfo<Article> titleByNameLimit(Integer pageNum, Integer pageSize
            , Map<String,Object> map, HttpServletRequest request) {

        HttpSession session = request.getSession();
        User loginUser = (User) session.getAttribute("loginUser");
        int id = loginUser.getId();

        map.put("uId",id);

        PageHelper.startPage(pageNum,pageSize);
        List<Article> dbCollectionArticleList=articleDao.titleByNameLimit(map);

        PageInfo<Article> articlePageInfo = new PageInfo<>(dbCollectionArticleList);
        return articlePageInfo;
    }
}
